<template>
    <div id="main" class="logincoent">
        <div class="rebackgroundimg">
            <div class="registruer">
                <div class="regrnamepwd">
                    <p class="iteljk">登录<span><a @click="$router.push({name:'register'})">未注册请先注册</a></span></p>
                    <div>
                        <div>
                            <ul class="ul_form">
                                <li class="user">
                                    <i class="iconfont icon-yonghu"></i>
                                    <input type="text" class="username" name="username" v-model="username"
                                        placeholder="请输入用户名">
                                </li>
                                <li class="pwdmia">
                                    <i class="iconfont icon-mima"></i>
                                    <input type="password" class="pwd" name="password" v-model="password"
                                        placeholder="请再次输入密码">
                                </li>
                            </ul>
                            <input type="submit" value="登录" class="sub" @click="toLogin">
                            <div style="color: red;font-size: 16px;text-align: center;margin-top: 20px;">
                                {{ msg }}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import { login } from '@/request/login'
export default {
    name: 'Login',
   
    data() {
        return {
            username: "",
            password: "",
            msg: "",
        }
    },
    methods: {
        toLogin() {
            if(this.username==""||this.password==""){
                this.$message.warning("请输入账号与密码")
                return
            }
            login({
                username:this.username,
                password:this.password
            }).then(res=>{
                if(res.code==200){
                    this.$message.success("登录成功")
                    localStorage.setItem("user",JSON.stringify(res.data))
                    this.$store.state.user = res.data
                    this.$bus.$emit('reload')
                    this.$router.push("/")
                }else{
                    this.$message.error(res.msg)
                }
            }).catch(err=>{
                console.log(err);
            })
        }
    },
};
</script>

<style scoped>
@import url('@/assets/css/lgoin.css');
</style>